package top.xzxsrq.datahelp.zhixin;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
import top.xzxsrq.common.utils.AdderIP;
import top.xzxsrq.datahelp.zhixin.config.FileConfig;
import top.xzxsrq.datahelp.zhixin.myenum.DataType;

import java.text.MessageFormat;

@SpringBootApplication
@Getter
@Setter
@Component
public class ZhixinApplication implements ApplicationListener<WebServerInitializedEvent> {

    private String dataType = DataType.ORACLE.name();

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(ZhixinApplication.class, args);
        FileConfig bean = run.getBean(FileConfig.class);
        System.err.println(MessageFormat.format("项目读取文件基础路径为: {0}", bean.getFileBasePath()));
        System.err.println("swagger地址 http://127.0.0.1:8899/doc.html");
    }

    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        int port = event.getWebServer().getPort();
        String ipv4 = AdderIP.getIPV4();
        System.err.println(MessageFormat.format("socket链接地址:    ws://{0}:{1}/socket", ipv4, port));
    }
}
